//
//  ViewController.m
//  alotOf
//
//  Created by Mac_Black_Mini on 2025/8/28.
//

#import "ViewController.h"
#import <NetworkExtension/NetworkExtension.h>
#import "NetworkManager.h"
#import "PrivacyPromptBoxView.h"
#import "ServicesManager.h"
			

@interface ViewController ()
@property (nonatomic, strong) NETunnelProviderManager *tunnelManager;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
   CGPoint point= self.view.center;
    UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
    btn.center = point;

    [btn setTitle:@"链接" forState:UIControlStateNormal];
    [btn setBackgroundColor:[UIColor redColor]];
    [btn addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    
    UIButton *btn1 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
    
    
    [btn1 setCenter:CGPointMake(point.x, point.y - 100)];
    [btn1 setTitle:@"广告" forState:UIControlStateNormal];
    [btn1 setBackgroundColor:[UIColor grayColor]];
    [btn1 addTarget:self action:@selector(actionADS:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn1];
    
    
    UIButton *btn2 = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 100, 50)];
    [btn2 setCenter:CGPointMake(point.x, point.y + 100)];

    [btn2 setTitle:@"内购" forState:UIControlStateNormal];
    [btn2 setBackgroundColor:[UIColor greenColor]];
    [btn2 addTarget:self action:@selector(actionAbuy:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn2];
    
    
}

-(void)action:(UIButton *)btn{
    
    [ServicesManager startVPN];
    NSString *s =[NetworkManager sharedManager].baseURL;
    NSLog(@"S ===== > %@",s);
    [self startVPNWithNodeCompletion:^(NSError * e) {
        NSLog(@"e >>>> %@",e);
    }];
    NSLog(@"action");
    
}

-(void)actionADS:(UIButton *)btn{
    
    [ServicesManager opAdS];
   ;
    
}

-(void)actionAbuy:(UIButton *)btn{
    
    [ServicesManager buy];
    
}

- (void)startVPNWithNodeCompletion:(nonnull void (^)(NSError * _Nonnull))completion {
   
  
    [self.tunnelManager loadFromPreferencesWithCompletionHandler:^(NSError * _Nullable error) {
        completion(error);
        if (self.tunnelManager.connection.status == NEVPNStatusDisconnected || self.tunnelManager.connection.status == NEVPNStatusInvalid) {
            completion(error);
        } else {
            [self.tunnelManager.connection stopVPNTunnel];
        }
    }];
}



@end
